package autoz.core.wizards;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;

public abstract class AbstractNewProjectCreationOperation implements IRunnableWithProgress  {

	// a reference to the page attributes
	protected NewProjectModel model;

	/**
	 * Create a new operation.
	 * @param model Project attributes
	 */
	public AbstractNewProjectCreationOperation(NewProjectModel model) {
		this.model = model;
	}

	/**
	 * Run the project creation task. This method is invoked by the Eclipse IDE after the 
	 * Project Creation Wizard is finished.
	 * 
	 * @param pMon progress monitor
	 */
	public abstract void run(IProgressMonitor pMon) throws InvocationTargetException, InterruptedException;

	/**
	 * Create the project directory.
	 * If the user has specified an external project location,
	 * the project is created with a custom description for the location.
	 * 
	 * @param project project
	 * @param monitor progress monitor
	 */
	protected abstract void createProject(IProject project, IProgressMonitor monitor) throws CoreException, InterruptedException;

	/**
	 * Create project's (sub)directory structure.
	 *  
	 * @param project project
	 * @param monitor progress monitor
	 */
	protected abstract void createProjectDirs(IProject project, IProgressMonitor monitor) throws CoreException ;

	/**
	 * Create a sub-directory to the given project's directory.
	 * @param project project
	 * @param monitor progress monitor
	 * @param dir directory name
	 */
	protected abstract void createDir(IProject project, IProgressMonitor monitor, String dir) throws CoreException;

		/**
		 * Create main file of the project from template.
		 * 
		 * @param project project
		 * @param monitor progress monitor
		 */
	protected abstract void createFile(IProject project, IProgressMonitor monitor, String bundleFilename, String projectFilename, Boolean useCommonBundle)
	throws CoreException ;

//	/**
//	 * 
//	 * @param project
//	 * @param monitor
//	 * @param path
//	 */
//	protected void addTemplates(IProject project, IProgressMonitor monitor, String path) {
//		Enumeration templateEnum;
//
//		try{
//			templateEnum = AutozPlugin.getDefault().getBundle().getEntryPaths(path);
//
//			// Trawl through each folder and add all files and folders
//			while (templateEnum.hasMoreElements()){
//				String elem = templateEnum.nextElement().toString();
//				
//				//	Don't want the subversion files to be included!
//				if (!elem.contains(".svn") && !elem.contains(".DS_Store")){
//					if (elem.endsWith("/")){
//						createDir(project,monitor,elem);
//						addTemplates(project,monitor,elem);
//					}
//					else{
//						createFile(project, monitor, elem, elem);
//					}
//				}
//			}
//
//		} catch (Exception ex) {
////			System.out.println(ex.getMessage());
//			ex.printStackTrace();
//		}		
//	}
}